package com.example.vue_shop.components.order.controller;

import com.example.vue_shop.components.order.service.OrderService;
import com.example.vue_shop.utils.ResultN;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author lipengwei
 */
@Api(tags = "订单管理")
@RestController
@RequestMapping("order")
public class ShopOrderController {

    @Resource(name = "orderServiceImpl")
    private OrderService orderService;

    /**
     * 获取订单列表.
     *
     * @param query    查询条件
     * @param pageNum  页数
     * @param pageSize 每页展示的数量
     * @return String
     */
    @ApiOperation(value = "获取订单列表", notes = "获取订单列表。")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "query", value = "查询条件"),
            @ApiImplicitParam(name = "pageNum", value = "页数", required = true,
                    dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示数量", required =
                    true, dataType = "int")
    })
    @GetMapping("/getOrderList")
    public String getOrderList(
            @RequestParam(required = false) String query,
            int pageNum, int pageSize) {
        try {
            Map<String, Object> orderList = orderService.getOrderList(query, pageNum, pageSize);
            return ResultN.success(orderList, "请求订单列表成功！");
        } catch (Exception e) {
            e.printStackTrace();
            return ResultN.error("获取订单列表失败！");
        }
    }
}
